package hotel.service.impl;

import hotel.service.IRoomStyleService;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import common.dao.BedTypeDAO;
import common.dao.RoomStyleDAO;
import common.pojo.RoomStyle;


@Scope("prototype")
@Service
public class RoomStyleService implements IRoomStyleService {
	@Resource
	private RoomStyleDAO roomStyleDAO;
	@Resource
	private BedTypeDAO bedTypeDAO;

	
	public List<RoomStyle> find(int start, int limit,String orderbys, String where) {
		List<RoomStyle> list=roomStyleDAO.findList(start, limit, orderbys, where);
		for(int i=0;i<list.size();i++){
			list.get(i).setBedTypeName(bedTypeDAO.findInfoById(list.get(i).getBedType()).getName());
		}
		return list;
	}

	
	public int getCount(String where){
		return roomStyleDAO.getCount(where);
	}


	public boolean save(RoomStyle roomStyle) {
		roomStyleDAO.save(roomStyle);
		return true;
	}
	
	public RoomStyle findInfoById(int id){
		return roomStyleDAO.findInfoById(id);
	}
	

	public boolean update(RoomStyle roomStyle) {
		roomStyleDAO.update(roomStyle);
		
		//记得又该价格
		//newDiscountDAO.update(roomStyle.getId(), 3, roomStyle.getPrice(), roomStyle.getRackRate());
		return true;
	}

	public boolean delete(String ids) {
		String[] id = StringUtils.split(ids,",");
		for(int i=0;i<id.length;i++){
			roomStyleDAO.update("update roomStyle set isDelete=1 where id="+Integer.valueOf(id[i]));
		}
		return true;
	}	
	
	public boolean restore(String ids) {
		String[] id = StringUtils.split(ids,",");
		for(int i=0;i<id.length;i++){
			roomStyleDAO.update("update roomStyle set isDelete=0 where id="+Integer.valueOf(id[i]));
		}
		return true;
	}


	public boolean completeDelete(String ids) {
		String[] id = StringUtils.split(ids,",");
		for(int i=0;i<id.length;i++){
			roomStyleDAO.delete(Integer.valueOf(id[i]));
		}
		return true;
	}
	
	public boolean update(String[] ids,String[] sorts){
    	for(int i=0;i<ids.length;i++)
    	{
    		roomStyleDAO.update("update roomStyle set sort="+sorts[i]+" where id="+ids[i]);
    	}
    	return true;
    }




}
